package com.itheima.reggie.common;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理类
 * @author Asin
 */

@RestControllerAdvice(annotations = {Controller.class, RestController.class})
public class GlobalExceptionHandler {


    @ExceptionHandler(CustomException.class)
    private R<String> customExceptionHandler(CustomException e){
        return R.error("服务器异常："+e.getMessage());
    }

    /**
     * 服务器发生异常直接走这个处理器，返回服务器异常给前端
     * @param e
     * @return
     */
    @ExceptionHandler
    public R<String> exceptionHandler(Exception e){
        e.printStackTrace();
        return R.error("服务器异常");
    }


}
